<template>
    <div class="material-store-item" @click="onMaterialDetail(item.id)">
        <div class="material-store-item__image">
            <img class="cover-image" :src="item.thumb_file +
                '?x-oss-process=image/watermark,image_' +
                toBase64(
                    'water/logo_white.png?x-oss-process=image/resize,P_30'
                ) +
                ',g_center,t_60'
                " />

            <!-- <div class="right-tag vip-tag">VIP</div> -->
            <div class="right-tag free-tag" v-if="item.sale_model == 1">
                限免
            </div>

            <div class="icon-360">
                <img :src="_oss_ + 'images/material-store/360.png'">
            </div>

            <div class="preview">
                <!-- <div class="left-tools">
                    <div class="btn" @click.stop>
                        <img
                            class="like-icon"
                            :src="`${_oss_}images/material-store/icon-like.png`"
                        />
                    </div>

                    <div class="btn" @click.stop>
                        <img
                            class="star-icon"
                            :src="`${_oss_}images/material-store/icon-star.png`"
                        />
                    </div>
                </div> -->

                <!-- 便捷查看按钮 -->
                <div class="view-btn" @click.stop="onPreview()">
                    便捷查看
                    <!-- <img
                        :src="`${_oss_}images/material-store/icon-arrow-bottom-2.png`"
                    /> -->
                </div>
            </div>
        </div>

        <div class="material-store-info">
            <div class="top">
                <div class="title">{{ item.name }}</div>
                <!-- <div class="tag">有动画</div> -->
            </div>

            <div class="bottom">
                <div class="price" v-if="item.sale_model == 1">免费</div>
                <div class="price" v-else>价格：￥{{ item.price }}</div>
                <div class="integral">
                    积分兑换：{{
                        item.sale_model == 1 || item.integral == 0
                        ? "免费"
                        : item.integral
                    }}
                </div>
            </div>
        </div>
        <DialogMaterialStorePreviewP ref="dialogRef" />
    </div>
</template>
<script setup>
const props = defineProps({
    item: {
        type: Object,
        default: () => ({}),
    },
});

const dialogRef = ref(null);

const onMaterialDetail = (id) => {
    navigateTo(`/materialStore/${id}.html`, {
        open: true,
    });
};

const onPreview = () => {
    dialogRef.value.show(props.item);
};
</script>
<style lang="scss" scoped>
.material-store-item {
    cursor: pointer;

    .material-store-item__image {
        position: relative;
        width: 100%;
        height: 200px;
        overflow: hidden;
        border-radius: 10px 10px 0 0;

        .icon-360 {
            width: 36px;
            height: 36px;
            position: absolute;
            bottom: 10px;
            right: 10px;

            img {
                width: 100%;
                height: 100%;
            }
        }

        &:hover {
            .icon-360 {
                display: none;
            }

            .preview {
                opacity: 1;
            }

            .cover-image {
                transform: scale(1.4);
            }
        }

        .cover-image {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: all 0.4s linear;
            display: block;
        }

        .preview {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.3);
            opacity: 0;
            transition: all 0.4s linear;

            .left-tools {
                position: absolute;
                top: 13px;
                left: 9px;

                .btn {
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    width: 26px;
                    height: 26px;
                    border-radius: 4px;
                    background-color: rgba($color: #000000, $alpha: 0.5);
                    margin-bottom: 11px;

                    img {
                        width: 14px;

                        &.like-icon {
                            height: 12px;
                        }

                        &.star-icon {
                            height: 14px;
                        }
                    }
                }
            }

            .view-btn {
                position: absolute;
                left: 50%;
                bottom: 15px;
                width: 86px;
                height: 28px;
                background: rgba(255, 255, 255, 0.1);
                border-radius: 4px;
                border: 1px solid #fff;
                transform: translateX(-50%);

                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 14px;
                color: #fff;
                user-select: none;

                img {
                    width: 8px;
                    height: 9px;
                    margin-left: 7px;
                }
            }
        }

        .right-tag {
            position: absolute;
            top: 0;
            right: 0;
            width: 46px;
            height: 26px;
            border-radius: 0 10px 0 10px;
            font-weight: 400;
            font-size: 12px;
            color: #ffffff;
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 9;
        }

        .vip-tag {
            background: linear-gradient(-90deg, #ff9c27, #ffc946);
        }

        .free-tag {
            background: linear-gradient(-90deg, #ff3527, #ff8846);
        }
    }

    .material-store-info {
        height: 70px;
        background-color: #fff;
        padding: 13px;
        border-radius: 0 0 10px 10px;

        .top {
            display: flex;
            align-items: center;

            .title {
                width: 100%;
                font-size: 16px;
                color: #333;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }

            .tag {
                font-size: 14px;
                color: #999;
                margin-left: auto;
                flex-shrink: 0;
            }
        }

        .bottom {
            display: flex;
            align-items: center;
            justify-content: space-between;
            font-size: 14px;
            color: #5085fb;
            margin-top: 12px;
        }
    }
}
</style>
